import React from 'react';
import {formatMessage} from './intl';
import PropTypes from 'prop-types';
import {Button} from 'antd';
import ExcelImportIntl from '../common/ExcelImportIntl';
import routes from './routes';

import fileTemplate from '../attachment/总代订单提报日期规则导入模板.xlsx';
const basePath = fetch.basePath || '';

const description = [
    formatMessage({
        id: 'calendarImport.step2.description1',
        defaultMessage: '总代编号、提报年份、提报日期 不能为空；'
    }),
    formatMessage({
        id: 'calendarImport.step2.description2',
        defaultMessage: '总代编号 + 提报年份 不可重复；'
    }),
    formatMessage({
        id: 'calendarImport.step2.description3',
        defaultMessage: '提报年份 应符合YYYY格式，如2019'
    }),
    formatMessage({
        id: 'calendarImport.step2.description5',
        defaultMessage: '提报日期格式：DD，范围在 1 到 31 ，允许输入多个值，如：1，2，3'
    }),
    formatMessage({
        id: 'calendarImport.step2.description4',
        defaultMessage: '提报年份大于等于当前年份'
    })
];

class DealerOrderSubmitRule extends React.PureComponent {
    constructor(props) {
        super(props);
        this.state = {loading: false};
    }

    onChange = () => this.setState({loading: !this.state.loading});

    onReturn = () => this.props.history.push(routes.query.url());

    render() {
        return ([
            <div key="return" className="page-toolbar">
                <Button type="primary" onClick={this.onReturn} disabled={this.state.loading}>
                    {formatMessage({
                        id: 'fileImport.btm.return',
                        defaultMessage: '返回'
                    })}
                </Button>
            </div>,
            <ExcelImportIntl
                key="import"
                template={this.props.dealerOrderSubmitRulesImportTemp}
                action={`${basePath}/parts/api/v1/dealerOrderSubmitRules/import`}
                description={description}
                beforeUpload={this.onChange}
                afterUpload={this.onChange}/>
        ]);
    }
}

DealerOrderSubmitRule.propTypes = {
    dealerOrderSubmitRulesImportTemp: PropTypes.func,
    history: PropTypes.object
};

import {connect} from 'react-redux';
import {
    dealerOrderSubmitRulesImportTemp
} from './actions';
const mapDispatchToProps = dispatch => ({
    dealerOrderSubmitRulesImportTemp: () => dispatch(dealerOrderSubmitRulesImportTemp())
});
export default connect(null, mapDispatchToProps)(DealerOrderSubmitRule);
